######DEFAULT######
/*
* 本文件内容不要人为修改，本文件由"python3 Christmas.py Input/MergeCode/LinkModule"生成
* 如果再次运行生成脚本，人为修改的代码将被删除
* 本文件模板请修改Christmas/Template/LinkModule/ErrorCode.templ
* 模块ErrorCode请修改src/main/java/com/stoprefactoring/once/module/??/Once.Link
* 修改结束后，终端执行"python3 Christmas.py Input/MergeCode/LinkModule"重新生成此文件
*
* The contents of this file should not be modified. This file is generated by "python3 Christmas.py Input/MergeCode/LinkModule"
* If the generation script is run again, the artificially modified code will be deleted
* This file template settings, please modify Christmas/Template/LinkModule/ErrorCode.templ
* Module ErrorCode settings, please modify src/main/java/com/stoprefactoring/once/module/??/Once.Link
* After the modification, execute "python3 Christmas.py Input/MergeCode/LinkModule" in the terminal to regenerate this file.
*/
package com.stoprefactoring.once.common;

import com.alibaba.fastjson2.JSONObject;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;

public enum ERRORCODE {
    ERR_OK,
    ERR_Ignore,
    ERR_Api_Exception,
    ERR_Api_Inner_Exception,
    ERR_Api_Switch_Lack,
    ERR_ApiInit_Param_Exception,
    ERR_ApiInit_ContentType_Illegal,
    ERR_Service_Exception,

@@enum@@
    ;

    private static HashMap<ERRORCODE, String[]> errorCodeMaps = new HashMap<>() {{
        put(ERR_OK, new String[]{"200", "OK"});
        put(ERR_Api_Exception, new String[]{"E-WS(API)", "API exception"});
        put(ERR_Api_Inner_Exception, new String[]{"E-WS(API)", "API Inner exception"});
        put(ERR_Api_Switch_Lack, new String[]{"E-WS(API)", "API Switch lack case"});
        put(ERR_ApiInit_Param_Exception, new String[]{"E-WS(API)", "API Init get request param exception"});
        put(ERR_ApiInit_ContentType_Illegal, new String[]{"E-WS(API)", "API Init request content type illegal"});
        put(ERR_Service_Exception, new String[]{"E-WS(SERVICE)", "Service exception"});

    @@errorCode@@
    }};

    public static boolean IsError(ERRORCODE code){
        if(code == ERRORCODE.ERR_OK){
            return false;
        }
        return true;
    }

    public static boolean IsError(ERRORCODE code, ERRORCODE[] skipList){
        if(code == ERRORCODE.ERR_OK) {
            return false;
        } else if (skipList.length!=0){
            List<ERRORCODE> tempList = Arrays.asList(skipList);
            return !tempList.contains(ERRORCODE.ERR_Ignore) && !tempList.contains(code);
        }
        return true;
    }

    public static JSONObject GetErrorCode(ERRORCODE code, JSONObject param){
        if(param.get("message") != null){
            return param;
        }

        String[] errorCodeList = (String[]) errorCodeMaps.get(code);
        if(errorCodeList == null){
            param.put("code", "unknown");
            param.put("message", "unknown");
        } else {
            param.put("code", errorCodeList[0]);
            param.put("message", errorCodeList[1]);
        }
        return param;
    }
}
######DEFAULT######